/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"FC3B9142-9BC1-4480-9FC6-81B0F9A0888A"}
 */
var cheque_anterior = null;

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"E6F7D465-FC58-43ED-A6B5-F1C8DC59DA0B"}
 */
function iniciar(firstShow, event) 
{
	databaseManager.setAutoSave(false);
	cheque_anterior = cheque_nro;
}

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"51D3B419-F4E1-4E98-892F-37CDACFEE278"}
 */
function onDataChange_cheque_nro(oldValue, newValue, event) 
{
	if(cheque_nro == null || utils.stringTrim(cheque_nro) == '')
	{
		globals.DIALOGS.showWarningDialog('Aviso','Debe ingresar numero cheque','OK')
		return false;
	}
	if (cheque_nro == cheque_anterior)
	{
		globals.DIALOGS.showWarningDialog('Aviso','Número cheque ingresado es igual al anterior','OK')
	}
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"27BE6806-0F0F-41F9-9002-DB05FE418F4C"}
 */
function cancelar(event) 
{
	var $win = application.getWindow('CHEQUE_MODIF')
	$win.hide()
	$win.destroy()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"2BDAB9B3-82E3-4F04-90F5-EB104242EAA0"}
 */
function confirmar(event) 
{
	var estado_dupli=ver_duplicado()
	if(estado_dupli==false)
	{   // ya tiene mensaje en ver_duplicado
		return;
	}
	
	if(databaseManager.saveData())
	{
		databaseManager.refreshRecordFromDatabase(foundset,0);
		globals.DIALOGS.showWarningDialog('Aviso','Cheque nro. ' + cheque_nro + '  modificado','OK')
		var $win = application.getWindow('CHEQUE_MODIF')
		$win.hide()
		$win.destroy()
		
	}
	else
	{
		globals.DIALOGS.showWarningDialog('Aviso','No se pudo modificar el Cheque','OK')
		var $win = application.getWindow('CHEQUE_MODIF')
		$win.hide()
		$win.destroy()
	}
		
}

/**
 * @properties={typeid:24,uuid:"DC12F356-5567-4F46-B8E6-42FDABB14527"}
 */
function salir() 
{
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	var $win = application.getWindow('CHEQUE_MODIF')
	$win.hide()
	$win.destroy()
}

/**
 * @properties={typeid:24,uuid:"1C1DB970-9A7B-40F9-81C8-9E6FFB2BA999"}
 */
function ver_duplicado() 
{
	globals.duplicacion_cheques(valor_id,banco_id,cheque_nro);
	if (globals.gfilas != 0)  // si es cero, no existe
	{ // ya existe , lo rechaza
		globals.DIALOGS.showWarningDialog('Aviso','Ya existe ' + cheques_to_valores.valor_descripcion + ' nro. ' + cheque_nro + ' de banco ' + cheques_to_cuentas_cyb.descripcion,'OK');
		return false;
	}
	return true
}
